package com.example.rabbitdemo.message;

import com.example.rabbitdemo.exchanger.direct.ExchangeMessageProducer;
import com.example.rabbitdemo.exchanger.fanout.BroadcastProducer;
import com.example.rabbitdemo.exchanger.topic.TopicProducer;
import com.example.rabbitdemo.simple.MessageProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/rabbit")
public class RabbitMQController {

    @Autowired
    private MessageProducer producer;

    @Autowired
    private ExchangeMessageProducer exchangeProducer;


    @Autowired
    private BroadcastProducer broadcastProducer;

    @Autowired
    private TopicProducer topicProducer;

    @GetMapping("/send")
    public String sendMessage(@RequestParam String message) {
        producer.sendMessage(message);
        return "消息发送成功: " + message;
    }


    @GetMapping("/direct/send")
    public String sendMessageDirect(@RequestParam String message) {
        exchangeProducer.sendOrderMessage(message);
        return "消息发送成功: " + message;
    }

    @GetMapping("/direct/send/payment")
    public String sendMessageDirectPay(@RequestParam String message) {
        exchangeProducer.sendPaymentMessage(message);
        return "消息发送成功: " + message;
    }


    //fanout , broadcast
    @GetMapping("/notification")
    public String notification(@RequestParam String message) {
        for (int i = 0; i < 10000; i++) {
            broadcastProducer.broadcastMessage(message + i);
        }
        return "广播成功: " + message;
    }

    @GetMapping("/topic")
    public String topic() {
            topicProducer.sendUsaWeather();
            topicProducer.sendUsaNews();
            topicProducer.sendEuropeNews();
        return "话题成功: ";
    }


}